<?php
class AutoAction extends Action {
    public function index(){
        //自动执行每月添加固定积分(优化中) &&date('d')==1
		if(isset($_GET['requestType'])){
            $dlog=D('Integral_log');
            $drule=D('Integral_rule');
            $dtype=D('Integral_type');
            $dmember=D('Member');
            $site=D('Site')->where(array('is_auto'=>1))->Field('id')->select();
            foreach($site as $val){
                $typeid=$dtype->where(array('site_id'=>$val['id'],'typename'=>'Binte'))->getField('id');
                $member=$dmember->where(array('site_id'=>$val['id'],'rule_id'=>array('neq','')))->select();
                foreach($member as $va){
                    $arr=explode(',',$va['rule_id']);    
                    foreach($arr as $v){
                        $rule=$drule->where(array('id'=>$v))->getField('id,name,remark,integralnum');  
                        $data['type_id']=$typeid;
                        $data['remark']=$rule[$v]['name'].'-'.$rule[$v]['remark'];
                        $data['member_id']=$va['id'];
                        $data['time']=time();
                        $data['rule_id']=$v;
                        $data['site_id']=$val['id'];
                        $data['changenum']=$rule[$v]['integralnum'];
                        
                        $dlog->add($data);
                    }
                }
            }
        }
    }
}